﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class sale : System.Web.UI.Page
    {
        public int PageIndex
        {
            get
            {
                return int.Parse(ViewState["pageIndex"].ToString());
            }
            set
            {
                ViewState["pageIndex"] = value;
            }
        }

        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount
        {
            get
            {
                return int.Parse(ViewState["PageCount"].ToString());
            }
            set
            {
                ViewState["PageCount"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                if (Session["Users"].ToString() != "sales" && Session["Users"].ToString() != "admin")
                {

                    Response.Write("<script>alert('你的权限不足！');location.href='Home.aspx';</script>");
                }
                // this.rpProducts.DataSource = new ProductBLL().GetModels();
                int rowsCount = new SalesBLL().Select("sales").Rows.Count; //行数
                PageCount = (rowsCount / 5);
                if (rowsCount % 5 != 0)
                {
                    PageCount++;
                }
                PageIndex = 1;
                GoPage();
            }
        }
        public void GoPage()
        {
            string TableName = "sales";
            this.rpPuchase.DataSource = new SalesBLL().FY(TableName, PageIndex);
            this.rpPuchase.DataBind();
        }
        protected void sel_Click(object sender, EventArgs e)
        {
            string TableName = "sales";
            string mz = this.sev.Value;
            this.rpPuchase.DataSource = new SalesBLL().SelectNo(TableName, mz);
            this.rpPuchase.DataBind();
        }

        protected void rpPuchase_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                string TableName = "sales";
                int id = int.Parse(e.CommandArgument.ToString());
                if (new SalesBLL().Del(TableName, id))
                {
                    GoPage();
                }
                DataTable w = new OrdersBLL().A();
                int ww = int.Parse(w.Rows[0]["ID"].ToString());
                new FundsBLL().SGai(ww);
                new FundsBLL().SD(ww);
            }
            else if (e.CommandName == "ok")
            {
                int id = int.Parse(e.CommandArgument.ToString());
                int a = 2;
                if (new SalesBLL().Sh(a, id))
                {
                    GoPage();
                }
            }
        }

        protected void btnPageFirst_Click(object sender, EventArgs e)
        {

            PageIndex = 1;
            GoPage();
        }

        protected void btnPagePre_Click(object sender, EventArgs e)
        {
            if (PageIndex > 1)
            {
                PageIndex--;

            }

            GoPage();
        }

        protected void btnPageNext_Click(object sender, EventArgs e)
        {
            if (PageIndex < PageCount)
            {
                PageIndex++;
            }
            GoPage();
        }

        protected void btnPageLast_Click(object sender, EventArgs e)
        {
            PageIndex = PageCount;
            GoPage();
        }
    }
}